home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Cinemagia.ro.ifs < prev    next >
Text File  |  2005-03-13  |  13KB  |  485 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Mihai Tudor
  8. Title=Cinemagia.ro
  9. Description=Cinemagia.ro (RO) import with picture
  10. Site=http://www.cinemagia.ro
  11. Language=RO
  12. Version=
  13. Requires=3.5.0
  14. Comments= tekman@go.ro
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program Cinemagia;
  23.  
  24. var
  25.   MovieName: string;
  26.   MovieURL: string;
  27.  
  28. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  29. var
  30.   i: Integer;
  31. begin
  32.   Result := -1;
  33.   if StartAt < 0 then
  34.     StartAt := 0;
  35.   for i := StartAt to List.Count-1 do
  36.     if Pos(Pattern, List.GetString(i)) <> 0 then
  37.     begin
  38.       Result := i;
  39.       Break;
  40.     end;
  41. end;
  42.  
  43. procedure AnalyzePage(Address: string);
  44. var
  45.   Page: TStringList;
  46. begin
  47.   Page := TStringList.Create;
  48.   Page.Text := GetPage(Address);
  49.  
  50.   if pos('Rezultatele cautarii', Page.Text) = 0 then
  51.   begin
  52.     AnalyzeMoviePage(Page)
  53.   end
  54.   else
  55.   begin
  56.     if pos('Nici un rezultat', Page.Text) > 0 then
  57.       ShowMessage('Sorry, no results were found for ' + MovieName)
  58.     else
  59.     begin
  60.       PickTreeClear;
  61.       AddMoviesTitles(Page);
  62.       if PickTreeExec(Address) then
  63.         AnalyzePage(Address);
  64.     end
  65.   end;
  66.   Page.Free;
  67. end;
  68.  
  69. function FindValue(BeginTag, EndTag: string; Page: TStringList; var LineNr: Integer; var Line: string): string;
  70. var
  71.   BeginPos, EndPos: Integer;
  72.   Value: string;
  73. begin
  74.   Result := '';
  75.   Value := '';
  76.   BeginPos := Pos(BeginTag, Line);
  77.   if BeginPos > 0 then
  78.   begin
  79.     BeginPos := BeginPos + Length(BeginTag);
  80.     if BeginTag = EndTag then
  81.     begin
  82.       Delete(Line,1,BeginPos-1);
  83.       BeginPos := 1;
  84.     end;
  85.     EndPos := pos(EndTag, Line);
  86.     while ((EndPos = 0) and (LineNr < Page.Count-1 )) do
  87.     begin
  88.       Value := Value + copy(Line, BeginPos, Length(Line) - BeginPos);
  89.       // Next Line
  90.       BeginPos := 1;
  91.       LineNr := LineNr + 1;
  92.       Line := Page.GetString(LineNr);
  93.       if Value = '' then
  94.         Exit;
  95.       EndPos := Pos(EndTag, Line);
  96.     end;
  97.     Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
  98.    end;
  99.   Result := Value;
  100. end;
  101.  
  102. procedure AnalyzeMoviePage(Page: TStringList);
  103. var
  104.   Line, Value, Value2: string;
  105.   IsFirst, LineNr, BeginPos, EndPos, DescrImport: Integer;
  106.   HasPressReviews : Integer;
  107.   PressReviewAddress : string;
  108. begin
  109.   LineNr := FindLine('<h1 class="movie">', Page, 0);
  110.   if LineNr > 2 then
  111.   begin
  112.     Line := Page.GetString(LineNr);
  113.     BeginPos := pos('<a href="', Line);
  114.     if BeginPos > 0 then
  115.       BeginPos := BeginPos + 9;
  116.     EndPos := pos('style=', Line);
  117.     if EndPos = 0 then
  118.       EndPos := Length(Line);
  119.     Value := copy(Line, BeginPos, EndPos - BeginPos - 2);
  120.     HTMLDecode(Value);
  121.     MovieURL := 'http://www.cinemagia.ro' + Value;
  122.  
  123.     // URL
  124.     SetField(fieldURL, MovieURL);
  125.    
  126.     Value := FindValue( '<b>', '</b>', Page, LineNr, Line);
  127.     HTMLDecode(Value);
  128.     SetField(fieldTranslatedTitle, Value);
  129.  
  130.     Value := FindValue( '<i>(', ')</i>', Page, LineNr, Line);
  131.     HTMLDecode(Value);
  132.     SetField(fieldYear, Value);
  133.  
  134.     LineNr := LineNr + 1;
  135.     Line := Page.GetString(LineNr);
  136.  
  137.     Value := FindValue( '<i>', '</i>', Page, LineNr, Line);
  138.     HTMLDecode(Value);
  139.     SetField(fieldOriginalTitle, Value);
  140.   end;
  141.  
  142.   LineNr := FindLine('<img src="/getimg.php?id=', Page, LineNr);
  143.   if LineNr > -1 then
  144.   begin
  145.     Line := Page.GetString(LineNr);
  146.     BeginPos := pos('<img src="/getimg.php?id=', Line);
  147.     if BeginPos > 0 then
  148.       BeginPos := BeginPos + 10;
  149.     EndPos := pos('&size=s"', Line);
  150.     if EndPos = 0 then
  151.       EndPos := Length(Line);
  152.     Value := copy(Line, BeginPos, EndPos - BeginPos + 6) + 'm';
  153.     HTMLDecode(Value);
  154.  
  155.     GetMoviePicture( 'http://www.cinemagia.ro' + Value);
  156.   end;
  157.  
  158.   LineNr := FindLine('Regia<br>', Page, LineNr);
  159.   if LineNr > -1 then
  160.   begin
  161.     Line := Page.GetString(LineNr);
  162.     BeginPos := pos('Regia<br>', Line);
  163.     if BeginPos > 0 then
  164.       BeginPos := BeginPos + 9;
  165.      
  166.     Delete( Line, 1, BeginPos);
  167.     EndPos := pos('<br>', Line);
  168.     if EndPos = 0 then
  169.       EndPos := Length(Line);
  170.     Value := copy(Line, 1, EndPos);
  171.  
  172.     BeginPos := pos('">', Value) + 2;
  173.     EndPos := pos('</a>', Value);
  174.     Value := copy(Value, BeginPos, EndPos - BeginPos);
  175.  
  176.     HTMLDecode(Value);
  177.     SetField(fieldDirector, Value);
  178.   end;
  179.  
  180.   LineNr := FindLine('Gen<br>', Page, LineNr);
  181.   if LineNr > -1 then
  182.   begin
  183.     Line := Page.GetString(LineNr);
  184.     BeginPos := pos('Gen<br>', Line);
  185.     if BeginPos > 0 then
  186.       BeginPos := BeginPos + 7;
  187.  
  188.     Delete( Line, 1, BeginPos);
  189.     EndPos := pos('<br>', Line);
  190.     if EndPos = 0 then
  191.       EndPos := Length(Line);
  192.     Value := copy(Line, 1, EndPos);
  193.  
  194.     Value2 := '';
  195.     repeat
  196.       BeginPos := pos('">', Value) + 2;
  197.       EndPos := pos('</span>', Value);
  198.       Value2 := Value2 + ', ' + copy(Value, BeginPos, EndPos - BeginPos);
  199.       Delete( Value, 1, EndPos + 8);
  200.     until pos('">', Value) < 1;
  201.    
  202.     Delete( Value2, 1, 2);
  203.  
  204.     HTMLDecode(Value2);
  205.     SetField(fieldCategory, Value2);
  206.   end;
  207.  
  208.   LineNr := FindLine('what=cast', Page, LineNr);
  209.   if LineNr > -1 then
  210.   begin
  211.     Line := Page.GetString(LineNr);
  212.     BeginPos := pos('<a href="', Line);
  213.     if BeginPos > 0 then
  214.       BeginPos := BeginPos + 9;
  215.  
  216.     EndPos := pos('" class', Line);
  217.     if EndPos = 0 then
  218.       EndPos := Length(Line);
  219.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  220.  
  221.     SetField(fieldActors, GetCast('http://www.cinemagia.ro' + Value));
  222.   end;
  223.  
  224.   HasPressReviews := 0;
  225.   IsFirst := 1;
  226.   Value2 := '';
  227.   LineNr := FindLine('Continuare</a>', Page, 0);
  228.   while (LineNr > -1) do
  229.   begin
  230.     Line := Page.GetString(LineNr);
  231.     BeginPos := pos('<a href="/movie.php', Line);
  232.     if BeginPos > 0 then
  233.       BeginPos := BeginPos + 9;
  234.      
  235.     EndPos := pos('&hist=0', Line);
  236.     if EndPos = 0 then
  237.       EndPos := Length(Line);
  238.     Value := copy(Line, BeginPos, EndPos - BeginPos + 7);
  239.     HTMLDecode(Value);
  240.  
  241.     if pos( 'what=pressreviews', Value) > 0 then
  242.     begin
  243.       PressReviewAddress := Value;
  244.       HasPressReviews := 1;
  245.     end
  246.     else
  247.     begin
  248.       if IsFirst = 1 then
  249.       begin
  250.         SetField(fieldDescription, GetDescriptions( Value));
  251.         IsFirst := 0;
  252.       end
  253.       else
  254.       begin
  255.         Value2 := Value2 + GetDescriptions( Value) + Chr(10) + Chr(13) + '===============';
  256.       end;
  257.     end;
  258.  
  259.     LineNr := FindLine('Continuare</a>', Page, LineNr + 1);
  260.   end;
  261.  
  262.   if HasPressReviews = 1 then
  263.   begin
  264.     Value2 := Value2 + GetPressReviews( PressReviewAddress);
  265.   end;
  266.  
  267.   SetField(fieldComments, Value2);
  268.  
  269.   //DisplayResults;
  270. end;
  271.  
  272. procedure GetMoviePicture( PictureAddress: string);
  273. begin
  274.    GetPicture(PictureAddress);
  275. end;
  276.  
  277. function GetCast(Address: string): string;
  278. var
  279.   Line, Value: string;
  280.   LineNr: Integer;
  281.   NoInfiniteLoop : Integer;
  282.   BeginPos, EndPos: Integer;
  283.   Page: TStringList;
  284. begin
  285.   Result := '';
  286.   Page := TStringList.Create;
  287.   Page.Text := GetPage(Address);
  288.   LineNr := FindLine('Distributie', Page, 0);
  289.   Value := '';
  290.   if LineNr > -1 then
  291.   begin
  292.     LineNr := LineNr + 2;
  293.     Line := Page.GetString(LineNr);
  294.    
  295.     NoInfiniteLoop := 0;
  296.     while ( pos('</table>', Line) < 1 ) and ( NoInfiniteLoop < 10) do
  297.     begin
  298.       NoInfiniteLoop := NoInfiniteLoop + 1;
  299.       Line := Page.GetString(LineNr + 1);
  300.       BeginPos := pos('">', Line);
  301.       if BeginPos > 0 then
  302.         BeginPos := BeginPos + 2;
  303.       EndPos := pos('</a>', Line);
  304.       if EndPos < 1 then
  305.         EndPos := Length(Line);
  306.       if Value <> '' then
  307.         Value := Value + '; ';
  308.       Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
  309.  
  310.       Line := Page.GetString(LineNr + 2);
  311.       BeginPos := pos('<td>', Line);
  312.       if BeginPos > 0 then
  313.         BeginPos := BeginPos + 4;
  314.       EndPos := pos('</td>', Line);
  315.       if EndPos < 1 then
  316.         EndPos := Length(Line);
  317.       if Value <> '' then
  318.         Value := Value + ' ';
  319.       Value := Value + '(in rolul ' + copy(Line, BeginPos, EndPos - BeginPos) + ')';
  320.    
  321.       Line := Page.GetString(LineNr + 4);
  322.       LineNr := LineNr + 4;
  323.     end;
  324.  
  325.     HTMLDecode(Value);
  326.  
  327.     Result := Value;
  328.   end;
  329.   Page.Free;
  330. end;
  331.  
  332. function GetDescriptions(Address: string): string;
  333. var
  334.   Line, Value: string;
  335.   LineNr: Integer;
  336.   BeginPos, EndPos: Integer;
  337.   Page: TStringList;
  338. begin
  339.   Result := '';
  340.   Page := TStringList.Create;
  341.   Page.Text := GetPage(Address);
  342.   LineNr := FindLine('Pagina principala', Page, 0);
  343.   if LineNr > -1 then
  344.   begin
  345.     Line := Page.GetString(LineNr + 1);
  346.     BeginPos := pos('<div class="section_title">', Line);
  347.     if BeginPos > 0 then
  348.       BeginPos := BeginPos + 27;
  349.     EndPos := pos('</div>', Line);
  350.     if EndPos < 1 then
  351.       EndPos := Length(Line);
  352.  
  353.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  354.     HTMLRemoveTags(Value);
  355.     Value := '<b>' + Value + '</b><br/>';
  356.  
  357.     LineNr := LineNr + 2;
  358.     repeat
  359.       Line := Page.GetString(LineNr);
  360.       BeginPos := pos('<div class="section">', Line);
  361.       if BeginPos > 0 then
  362.         BeginPos := BeginPos + 21
  363.       else
  364.         BeginPos := 1;
  365.       EndPos := pos('</div>', Line);
  366.       if EndPos < 1 then
  367.         EndPos := Length(Line) + 1;
  368.       if Value <> '' then
  369.         Value := Value + ' ';
  370.       Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
  371.       LineNr := LineNr + 1;
  372.     until (pos('</div>', Line) > 0) or (LineNr = Page.Count);
  373.     HTMLDecode(Value);
  374.  
  375.     Result := Value;
  376.   end;
  377.  
  378.   Page.Free;
  379. end;
  380.  
  381. function GetPressReviews(Address: string): string;
  382. var
  383.   Line, Value, Value2: string;
  384.   LineNr: Integer;
  385.   BeginPos, EndPos: Integer;
  386.   Page: TStringList;
  387. begin
  388.   Result := '';
  389.   Value2 := '';
  390.   Value := '';
  391.   Page := TStringList.Create;
  392.   Page.Text := GetPage(Address);
  393.   LineNr := FindLine('<div class="section_title">', Page, 0);
  394.   while LineNr > -1 do
  395.   begin
  396.     Line := Page.GetString(LineNr);
  397.     if pos('a href=', Line) < 1 then
  398.     begin
  399.       BeginPos := pos('<div class="section_title">', Line);
  400.       if BeginPos > 0 then
  401.         BeginPos := BeginPos + 27;
  402.       EndPos := pos('</div>', Line);
  403.       if EndPos < 1 then
  404.         EndPos := Length(Line);
  405.  
  406.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  407.       HTMLRemoveTags(Value);
  408.       Value := '<b>' + Value + '</b><br/>';
  409.  
  410.       LineNr := LineNr + 2;
  411.       repeat
  412.         Line := Page.GetString(LineNr);
  413.         BeginPos := pos('<div class="section">', Line);
  414.         if BeginPos > 0 then
  415.           BeginPos := BeginPos + 21
  416.         else
  417.           BeginPos := 1;
  418.         EndPos := pos('</div>', Line);
  419.         if EndPos < 1 then
  420.           EndPos := Length(Line) + 1;
  421.         if Value <> '' then
  422.           Value := Value + ' ';
  423.         Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
  424.         LineNr := LineNr + 1;
  425.       until (pos('</div>', Line) > 0) or (LineNr = Page.Count);
  426.    
  427.       Value2 := Value2 + Value;
  428.     end
  429.     else
  430.       LineNr := LineNr + 1;
  431.  
  432.     LineNr := FindLine('<div class="section_title">', Page, LineNr);
  433.   end;
  434.  
  435.   HTMLDecode(Value2);
  436.  
  437.   Result := Value2;
  438.  
  439.   Page.Free;
  440. end;
  441.  
  442. procedure AddMoviesTitles(Page: TStringList);
  443. var
  444.   Line: string;
  445.   LineNr: Integer;
  446.   MovieTitle, MovieAddress: string;
  447.   StartPos: Integer;
  448. begin
  449.   LineNr := FindLine( 'Rezultatele cautarii', Page, 0);
  450.   if LineNr > -1 then
  451.   begin
  452.     PickTreeAdd('Filme', '');
  453.     LineNr := LineNr + 3;
  454.     Line := Page.GetString(LineNr);
  455.     repeat
  456.       StartPos := pos('href="', Line) + 5;
  457.       Delete(Line, 1, StartPos);
  458.       MovieAddress := Copy(Line, 1, pos('"', Line) - 1);
  459.       StartPos := Pos('">', Line) + 2;
  460.       MovieTitle := Copy(Line, StartPos, Pos('</i>', Line) - StartPos);
  461.       HTMLDecode(Movietitle);
  462.       Delete( Movietitle, Pos('</a>', Movietitle), 4);
  463.       Delete( Movietitle, Pos('<i>', Movietitle), 3);
  464.       PickTreeAdd(MovieTitle, 'http://www.cinemagia.ro' + MovieAddress);
  465.       LineNr := LineNr + 1;
  466.       Line := Page.GetString(LineNr);
  467.     until Pos('</div>', Line) > 0;
  468.   end;
  469. end;
  470.  
  471. begin
  472.   if CheckVersion(3,5,0) then
  473.   begin
  474.     MovieName := GetField(fieldOriginalTitle);
  475.     if MovieName = '' then
  476.       MovieName := GetField(fieldTranslatedTitle);
  477.     if Input('Cinemagia.RO Import', 'Enter the title of the movie:', MovieName) then
  478.     begin
  479.       AnalyzePage('http://www.cinemagia.ro/search.php?q=' + UrlEncode(MovieName) + '&hist=0');
  480.     end;
  481.   end
  482.   else
  483.   ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  484. end.
  485.